//
//  LSZNicknameVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/9/30.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZNicknameVC.h"

@interface LSZNicknameVC ()

@end

@implementation LSZNicknameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改昵称";
    self.view.backgroundColor = RGBColor(247, 247, 247);

    UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 20+NAVIGATION_BAR_HEIGHT, ScreenWidth-20, 40)];
    textField.tag = 1;
    [textField.layer setMasksToBounds:YES];
    [textField.layer setCornerRadius:5];
    textField.layer.borderColor = [ RGBColor(89, 196, 120) CGColor];
    textField.layer.borderWidth = 1;
    textField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:textField];
    
    UIButton * butOk = [[UIButton alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(textField.frame)+100, ScreenWidth-20, 40)];
    butOk.backgroundColor = RGBColor(89, 196, 120);
    [butOk.layer setMasksToBounds:YES];
    [butOk.layer setCornerRadius:5];
    [butOk setTitle:@"确定" forState:UIControlStateNormal];
    [butOk addTarget:self action:@selector(clickButOk) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:butOk];
}
#pragma mark - 确定按钮
-(void)clickButOk
{
    UITextField * textField = [self.view viewWithTag:1];
    if (textField.text.length == 0) {
        [SVProgressHUD showErrorWithStatus:@"请填写你要修改成的昵称!"];
        [SVProgressHUD dismissWithDelay:1];
    }else{
 
        __weak typeof(self) weakSelf = self;
        NSDictionary *input = @{@"username":textField.text};
        NSString * url= [NSString stringWithFormat:@"%@/user/set_username",URLTotal];
        [LSZRequestData initregistrationSendVerificationCode:input url:url :^(BOOL isOK, NSString * str, NSDictionary * dic) {
            if (isOK == YES) {
                [SVProgressHUD showSuccessWithStatus:@"修改昵称成功"];
                [SVProgressHUD dismissWithDelay:1];
                [weakSelf performSelector:@selector(clickReturn) withObject:nil afterDelay:1.5];
            }else{
                [SVProgressHUD showErrorWithStatus:str];
            }
        }];
    }
}
-(void)clickReturn
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
